package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.IdoflawyersBean;
import com.example.myapplication.ShuJu.LawyerlistBean;
import com.example.myapplication.ShuJu.MyconsultationBean;
import com.example.myapplication.ShuJu.TopchoicelawyeBean;
import com.example.myapplication.lawyer.AddconsultationlistActivity;
import com.example.myapplication.lawyer.ConsultationlistActivity;
import com.example.myapplication.lawyer.LawyerActivity;
import com.example.myapplication.lawyer.LawyerListActivity;
import com.example.myapplication.lawyer.LawyerconsultationActivity;
import com.example.myapplication.lawyer.LawyerlistpageActivity;

import java.util.List;

public class LawyerlistApter extends  RecyclerView.Adapter<LawyerlistApter.Myhot>{
    private Context context;
    private List<LawyerlistBean.RowsBean> list;
    private List<MyconsultationBean.RowsBean> MyconsultationList;


    public LawyerlistApter(Context context, List<LawyerlistBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }



    public LawyerlistApter() {
    }

    @NonNull
    @Override
    public LawyerlistApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_topchoicelawye, null);
        return new LawyerlistApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull LawyerlistApter.Myhot holder, int position) {
        Glide.with(context).load(TokenBean.IP+list.get(position).getAvatarUrl()).into(holder.img_topchoicelawyy);
        holder.name_topchoicelawyy.setText(list.get(position).getName());
        holder.text_topchoicelawyy.setText(list.get(position).getLegalExpertiseName());
        holder.num_topchoicelawyy.setText(String.valueOf(list.get(position).getServiceTimes()));
        holder.year_topchoicelawyy.setText(list.get(position).getWorkStartAt());
        if( context instanceof LawyerListActivity){
            //进入律师列表页
            holder.re_topchoicelawyy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, LawyerlistpageActivity.class);
                    intent.putExtra("LawyerlistpageActivityID",String.valueOf(list.get(position).getId()));
                    context.startActivity(intent);
                }
            });
        }else if( context instanceof AddconsultationlistActivity){
            //点击进入添加咨询
            holder.re_topchoicelawyy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //咨询详情页
                    Intent intent = new Intent(context, LawyerconsultationActivity.class);
                    intent.putExtra("LawyerconsultationActivityID",String.valueOf(list.get(position).getId()));
                    context.startActivity(intent);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final ImageView img_topchoicelawyy;
        private final TextView name_topchoicelawyy;
        private final TextView text_topchoicelawyy;
        private final TextView num_topchoicelawyy;
        private final TextView year_topchoicelawyy;
        private final RelativeLayout re_topchoicelawyy;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            img_topchoicelawyy = itemView.findViewById(R.id.img_topchoicelawyy);
            name_topchoicelawyy = itemView.findViewById(R.id.Name_topchoicelawyy);
            text_topchoicelawyy = itemView.findViewById(R.id.text_topchoicelawyy);
            num_topchoicelawyy = itemView.findViewById(R.id.num_topchoicelawyy);
            year_topchoicelawyy = itemView.findViewById(R.id.year_topchoicelawyy);
            re_topchoicelawyy = itemView.findViewById(R.id.re_topchoicelawyy);
        }
    }
}
